package cn.codewen.service.impl;

import cn.codewen.dao.impl.UserDaoImpl;
import cn.codewen.pojo.User;
import cn.codewen.service.UserService;

public class UserServiceImpl implements UserService {
    @Override
    public User checkUser(String username, String password) {

        //创建DAO对象
        UserDaoImpl userDao = new UserDaoImpl();
        //调用userDao的方法  取到用户
        User user = userDao.getOneByUsername(username);
        //判断密码是否正确
        if (user!=null && user.getPassword().equals(password)){

            return  user;

        }else {
            return null;
        }

    }

    @Override
    public Boolean regUser(User user) {
        //创建DAO对象
        UserDaoImpl userDao = new UserDaoImpl();
        //调用userDao的方法  取到用户
        User rs = userDao.insert(user);
        //判断user1是否存在
        if (rs!=null){
            return true;
        }else {
            return  false;
        }
    }
}
